﻿namespace iFinance.Modules.Authorization
{
    using System.Windows;
    using System.Windows.Controls;
    using iFinance.Controls;

    public partial class RegisterView : ChildWindow
    {
        public RegisterView()
        {
            InitializeComponent();
            this.btnRegister.Click += new RoutedEventHandler(btnRegister_Click);
        }

        void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            foreach (var item in spItems.Children)
            {
                var input = item as ValidationInput;
                if (input != null)
                {
                    input.GetBindingExpression(ValidationInput.ValueProperty).UpdateSource();
                }
            }
            var viewModel = (this.DataContext as iFinance.Modules.Authorization.ViewModels.RegisterViewModel);
            if (viewModel != null && !viewModel.HasErrors)
            {
                var result = viewModel.Register();
                if (result)
                {
                    MessageBox.Show("注册成功!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("注册失败!");
                }
            }           
        }
    }
}
